package com.hmdp.config;

import com.hmdp.interceptor.LoginInterceptor;
import com.hmdp.interceptor.refreshTokenInterceptor;
import com.sun.corba.se.impl.resolver.SplitLocalResolverImpl;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author wzy
 * @Date 2024/2/4 21:10
 * @description:
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截器
        registry.addInterceptor(new LoginInterceptor())//添加拦截器
                .excludePathPatterns(
                        "/shop/**",
                        "/shop-type/**",
                        "/blog/hot",
                        "/voucher/**",
                        "/user/code",
                        "/user/login"
                ).order(1);//order(1)值越大后执行
        //刷新token拦截器
        registry.addInterceptor(new refreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);//先执行
    }
}
